package com.itheima.mapper;

import com.itheima.pojo.Flux;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import java.time.LocalDateTime;
import java.util.List;

@Mapper
public interface FluxMapper {

    // 插入数据
    @Insert("insert into flux (timestamp, fc, le, h, fch4) " +
            "values (#{timestamp}, #{fc}, #{le}, #{h}, #{fch4})")
    void add(Flux flux);

    // 查询数据，根据TimeStamp
    @Select("select * from flux where timestamp = #{timestamp}")
    Flux findFluxByTimestamp(LocalDateTime timestamp);

    // 查询数据，返回在TimeStamp在startTime到EndTime之间的所有数据
    @Select("select * from flux where timestamp between #{startTime} and #{endTime}")
    List<Flux> findFluxByTimeRange(LocalDateTime startTime, LocalDateTime endTime);

    // 更新数据
    @Update("update flux set fc = #{fc}, le = #{le}, h = #{h}, fch4 = #{fch4} where timestamp = #{timestamp}")
    void update(Flux flux);

    // 查询数据库中现有数据的最新日期的当天的全部数据
    @Select("select * from flux where date(timestamp) = (select max(date(timestamp)) from flux)")
    List<Flux> findFluxInLatestDayData();

    // 查询表中的数据总条数
    @Select("select count(*) from flux")
    Integer findFluxAllNumber();
}
